<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set the size for future connection pools.</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.pooldebug.html">Mongo::poolDebug</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongo.setslaveokay.html">Mongo::setSlaveOkay</a></div>
 <div class="up"><a href="class.mongo.html">Mongo</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongo.setpoolsize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Mongo::setPoolSize</h1>
  <p class="verinfo">(PECL mongo &gt;=1.2.0)</p><p class="refpurpose"><span class="refname">Mongo::setPoolSize</span> &mdash; <span class="dc-title">Set the size for future connection pools.</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongo.setpoolsize-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">bool</span> <span class="methodname"><strong>Mongo::setPoolSize</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span>
   )</div>


  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">This method has been <em class="emphasis">DEPRECATED</em> as of version
    1.2.3. Relying on this feature is highly discouraged.  Please use
    <span class="function"><a href="mongopool.setsize.html" class="function">MongoPool::setSize()</a></span> instead.
   </p>
  </div>

  <p class="para">
   Sets the max number of connections new pools will be able to create.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongo.setpoolsize-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>

      <em><code class="parameter">size</code></em>
     </dt>

     <dd>

      <p class="para">
       The max number of connections future pools will be able to create.
       Negative numbers mean that the pool will spawn an infinite number of
       connections.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongo.setpoolsize-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the former value of pool size.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-mongo.setpoolsize-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="mongo.setpoolsize.example.basic">
    <p><strong>Example #1 <span class="function"><strong>Mongo::setPoolSize()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     If you set the pool size to <em>n</em> and then create
     <em>n</em> connections, attempting to create an
     <em>n+1</em>st connection will throw a
     <a href="class.mongoconnectionexception.html" class="classname">MongoConnectionException</a>.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;only&nbsp;allow&nbsp;one&nbsp;connection&nbsp;to&nbsp;a&nbsp;server<br /></span><span style="color: #0000BB">Mongo</span><span style="color: #007700">::</span><span style="color: #0000BB">setPoolSize</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;creates&nbsp;one&nbsp;connection&nbsp;to&nbsp;localhost:27017<br /></span><span style="color: #0000BB">$m1&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Mongo</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;attempt&nbsp;to&nbsp;create&nbsp;a&nbsp;second&nbsp;connection&nbsp;to&nbsp;localhost:27017<br />//&nbsp;only&nbsp;one&nbsp;connection&nbsp;is&nbsp;allowed,&nbsp;so&nbsp;this&nbsp;will&nbsp;throw&nbsp;an&nbsp;exception<br /></span><span style="color: #0000BB">$m2&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Mongo</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Fatal error: Uncaught exception &#039;MongoConnectionException&#039; with message &#039;no more connections in pool&#039; in /path/to/php/script.php:10
Stack trace:
#0 /path/to/php/script.php(10): Mongo-&gt;__construct()
#1 {main}
  thrown in /path/to/php/script.php on line 10
</pre></div>
    </div>
   </div>
  </p>
 </div>



 <div class="refsect1 seealso" id="refsect1-mongo.setpoolsize-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mongo.getpoolsize.html" class="function" rel="rdfs-seeAlso">Mongo::getPoolSize()</a> - Get pool size for connection pools</span></li>
    <li class="member"><span class="function"><a href="mongo.pooldebug.html" class="function" rel="rdfs-seeAlso">Mongo::poolDebug()</a> - Returns information about all connection pools.</span></li>
    <li class="member">The <a href="mongo.connecting.html" class="link">connection</a> documentation.</li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.pooldebug.html">Mongo::poolDebug</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongo.setslaveokay.html">Mongo::setSlaveOkay</a></div>
 <div class="up"><a href="class.mongo.html">Mongo</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
